package com.cardosystems.infra;

import java.util.List;

import jsystem.framework.system.SystemObjectImpl;

import com.googlecode.gmail4j.GmailMessage;
import com.googlecode.gmail4j.http.HttpGmailConnection;
import com.googlecode.gmail4j.rss.RssGmailClient;

public class GmailClient extends SystemObjectImpl {

	com.googlecode.gmail4j.GmailClient client;
	HttpGmailConnection conn;
	String password;
	String username;
	
	

	@Override
	public void init() throws Exception {
		super.init();
		client = new RssGmailClient();
		conn = new HttpGmailConnection(username, password.toCharArray());
		//conn.setLoginCredentials(username, password.toCharArray());
		client.setConnection(conn);
	}
	
	public List<GmailMessage> getUnreadMesseges() throws Exception{
		final List<GmailMessage> messages = client.getUnreadMessages();
		return messages;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

}
